'use strict';
//define(['js/module.js'], function(controllers) {
angular.module('common.actionSelectMulti', [])

	.controller('actionSelectMultiCtrl'
			,['$scope', '$rootScope', 'BizData', '$uibModalInstance','params', 'title'
			   , f]);//控制器结束
	function f($scope, $rootScope, BizData, $uibModalInstance, params, title
			   ) {

var Model = this;



/**
name:bizData#onBeforeDelete
description: <b>[回调型事件]</b>业务数据删除前
@param {object} event 它的结构如下:<br/>
{
	"source":组件的js对象
	,"cancel":可修改	，设置为true后中断当前delete动作
	,"deleteIDList":删除的行Id数组
}
*/
Model.dataSysActionBeforeDelete = function(event) {
//	alert(event.deleteIDList[0]);
}
/**
name:bizData#onAfterDelete
description: <b>[回调型事件]</b>业务数据删除后
@param {object} event 
<br/><b>结构如下：</b>
<xmp> 
{
	"source" : 组件的js对象,
	"deleteIDList" : 删除的行Id数组
}
</xmp>	
*/
Model.dataSysActionAfterDelete = function(event) {
//	alert('删除之后！')
}






/**
name:bizData#onIndexChanged
description: <b>[回调型事件]</b>行记录变化
@param {object} event 
<br/><b>结构如下：</b>
<xmp> 
{
	"source" : 组件的js对象,
	"rowID" : 行Id,
	"rowIndex" : 行索引
}
</xmp>	
*/
Model.dataSysActionIndexChanged = function(event) {
}

/**
name:bizData#onDataChanged
description: <b>[回调型事件]</b>数据发生变化（包括新增、刷新、删除、修改引起的变化），感知从data的变化
@param {object} event 
<br/><b>结构如下：</b>
<xmp> 
{
	"source" : 组件的js对象,
	"changedSource" ：触发变化的组件的js对象，当从data触发时返回从data对象,
	"selfChanged" : 是否自身变化，false：从data触发的变化,
	"type" : 触发变化的类型，包括：new、delete、refresh、valueChanged、clear，其他参数根据触发类型不同给出不同参数，参考onAfterNew等事件参数
}
</xmp>	
*/
Model.dataSysActionDataChanged = function(event) {
}

/**
name:bizData#onValueChanged
description: <b>[回调型事件]</b>数据变化
@param {object} event 
<br/><b>结构如下：</b>
<xmp> 
{
	"source" : 组件的js对象,
	"column" : 关系,
	"rowIndex" : 行索引,
	"value" : 新值,
	"originalValue" : 旧值
}
</xmp>	
*/
//输入值变化，监视input的输入，ng-change
Model.dataSysActionValueChanged = function(event) {

}


/**
name:bizData#onBeforeNew
description: <b>[回调型事件]</b>业务数据新增前
@param {object} event 它的结构如下:<br/>{"source":组件的js对象,"cancel":可修改，设置为true后中断当前new动作}
*/
Model.dataSysActionBeforeNew = function(event) {

};
/**
* name:bizData#onAfterNew description: <b>[回调型事件]</b>业务数据新增后
* 
* @param event
*            它的结构如下:<br/>{"source":组件的js对象,"id":新增的行Id}
*/
Model.dataSysActionAfterNew = function(event){

}

/**
name:bizData#onBeforeRefresh
description: <b>[回调型事件]</b>业务数据刷新前
@param {object} event 
<br/><b>结构如下：</b>
<xmp> 
{
	"source" : 组件的js对象,
	"cancel" : 可修改，设置为true后中断当前刷新动作
}
</xmp>	
*/
Model.dataSysActionBeforeRefresh = function(event){
}
/**
name:bizData#onAfterRefresh
description: <b>[回调型事件]</b>业务数据刷新后
@param {object} event 
<br/><b>结构如下：</b>
<xmp> 
{
	"source" : 组件的js对象
	"limit" : 页大小, 
	"offset" : 偏移,
	"success" : 是否成功刷新
}
</xmp>	
*/
Model.dataSysActionAfterRefresh = function(event){
	var sActions = Model.params.sActions;
	if(sActions!=null){
		//循环data
		for(var i=0;i<$scope.dataSysAction.rows.length;i++){
			var action = $scope.dataSysAction.rows[i].actionCode.value;
			if(sActions.indexOf(action)!= -1){
				$scope.dataSysAction.rows[i].userdata.checked = true;
			}
		}
		
	}
}


var options = {};
options.container = Model;
options.concept = 'SysAction';
options.name = 'dataSysAction';
options.url = $rootScope.path;
options.httpUrl = $rootScope.getServiceName();
options.creater = '';
options.reader = '/backcenter/sysAction/list/query';
options.writer = '/backcenter/sysAction/list/save';
options.deleter = '/backcenter/sysAction/list/delete';
options.idColumnDefine = "fID";
options.idColumnName = "fID";
options.defCols = {fID:{name:"fID",type:"String",label:""},systemFullID:{name:"systemFullID",type:"String",label:""},actionCode:{name:"actionCode",type:"String",label:""},actionName:{name:"actionName",type:"String",label:""},actionDescribe:{name:"actionDescribe",type:"String",label:""},version:{name:"version",type:"Integer",label:""}};
options.isTree = false;
options.parentRelation = 'sParent';
options.nodeKindRelation = 'sNodeKind';
options.nodeLevelRelation = 'sLevel';
options.nodeSortRelation = "sSequence";
options.pathRelation = 'sFID';
options.directDeleteMode = false;
options.limit = -1;

options.onIndexChanging = null;
options.onIndexChanged = Model.dataSysActionIndexChanged;
options.onBeforeNew = Model.dataSysActionBeforeNew;
options.onAfterNew = Model.dataSysActionAfterNew;
options.onBeforeDelete = Model.dataSysActionBeforeDelete;
options.onAfterDelete = Model.dataSysActionAfterDelete;
options.onValueChanged = Model.dataSysActionValueChanged;
options.onDataChanged = Model.dataSysActionDataChanged;
options.onBeforeRefresh = Model.dataSysActionBeforeRefresh;
options.onAfterRefresh = Model.dataSysActionAfterRefresh;

$scope.dataSysAction = new BizData(options);

//监视对象中的所有变动
//$scope.dataSysAction.deregRows = $scope.$watch('dataSysAction.rows',$scope.dataSysAction.watchRows,true);//true代表深度监视，包括对象的属性，而不是简单的一个值
//////////////////////////////////////////////


//////////////////////对话框使用开始//////////////////////////////////////

//模态窗口打开之后执行的事件
$uibModalInstance.opened.then(function(){
	//接收调用对话框的参数
	$scope.title = title;  
	Model.params = params;  
	
	$scope.dataSysAction.filter = "SysAction.systemFullID = '" + params.id + "'";
	$scope.dataSysAction.refreshData();

});  

Model.ok = function () {  
	//保存成功
	//打包数据
	var event = {};
	var data = [];
	
	//循环data
	for(var index=0;index<$scope.dataSysAction.rows.length;index++){
		if($scope.dataSysAction.rows[index].userdata.checked){
	    	
	    	var sourceRow = $scope.dataSysAction.rows[index];
	    	var row = {};
			//循环行中的列，判断变化点是哪一个
			for(var obj in sourceRow){
				if(obj!='$$hashKey' && obj!='userdata'){
					row[obj] = sourceRow[obj].value;
				}
			}
	    	
	    	data.push(row);
			
		}
	}
	
	event.data = data;
	$uibModalInstance.close(event);  
};  


Model.cancel = function () {  
 $uibModalInstance.dismiss('cancel');  
};    

//表格标题中的选择对话框ng-model
$scope.checkboxValue = false;
//表格标题中的选择对话框click事件
Model.checkboxClick = function () {  
	for(var index=0;index<$scope.dataSysAction.rows.length;index++){
		$scope.dataSysAction.rows[index].userdata.checked=$scope.checkboxValue;
	}
};    
//////////////////////对话框使用结束//////////////////////////////////////




return Model;



}	
	
//});
